package GC_requestSetInfo;


import static org.junit.Assert.assertEquals;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import FamilyTherapy.Game;
import FamilyTherapy.GCWindow;
import FamilyTherapy.Player;

public class testGCWindow_requestSetInfo_2 {

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testRequestSetInfo_2() {
		//int result;
		Game game = new Game();
		game.setNoOfPlayer(2);
		GCWindow gwindow = new GCWindow();
		Player[] p =new Player[2];
		//for output
		final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
		System.setOut(new PrintStream(outContent));
	
		
		String expected = "Player 0, please input your name: \n" + 
		
		"0.Grandpa 1.Grandma 2.Father 3.Mother 4.Son 5.Daughter " +
		"\nPlayer 0, please select your role: \n" + 
		"Please input a number between 0 and 5.\n" +		
		"Please input an integer.\n" + 
		"Please input an integer.\n" + 
		"0.Grandpa 1.Grandma 2.Father 3.Mother 4.Son 5.Daughter " +
		"\nPlayer 0, please select your role: \n"  +		
		"Player 1, please input your name: \n"+
		"0.Grandpa 1.Grandma 2.Father 3.Mother 4.Son 5.Daughter " + 
		"\nPlayer 1, please select your role: \n" ;
		//for input
		String data = "a 8 t + 0 b 2"; 	//data to be input 
		InputStream stdin = System.in; 
		try {   
			System.setIn(new ByteArrayInputStream(data.getBytes()));	//put data to input stream
			gwindow.requestSetInfo(game,p);	//for getting data from input stream
		} 
		finally {  
			System.setIn(stdin); 	//reset input stream as System.in
		} 
		
		//for testing
		assertEquals(expected,outContent.toString());
		
	}

}
